/**
* 
* DPM for LEAT exercice with leat PROCESSOR  
* see <a href="{@docRoot}/Documentation/report.html"> for more information</a>
*  Copyright (c) 2009 Ecole Centrale de Nantes IRCCyN
* @author: Urunuela Richard
* @version 3.2
*/

package storm.DPMS;

import java.util.ArrayList;
import java.util.Iterator;

import storm.Processors.LEATProcessor;
import storm.Processors.Processor;
/**
 * 
 * @author richard
 *
 */
public class DPM_P_LEAT extends DPM {
	

	/**
	 * au d??marrge tout les processeurs sont min freq;
	 */
	public void init(){
		ArrayList cpus = this.Kernel.getTasksListeManager().getALLProcessors();
		Iterator I = cpus.iterator();
		while (I.hasNext()){
			Processor P= (Processor) I.next();
		/*	if (P instanceof LEATProcessor){
				
				LEATProcessor LP = (LEATProcessor) P;
				LP.setFreq(5);
			}*/
		}
	}
	/**
	 * 
	 */
	public void onTick(){
		
		ArrayList cpus = this.Kernel.getTasksListeManager().getALLProcessors();
		Iterator I = cpus.iterator();
		while (I.hasNext()){
			Processor P= (Processor) I.next();
			if (P instanceof LEATProcessor){
				//Change frequency in time 
				LEATProcessor LP = (LEATProcessor) P;
			/*	if (this.Kernel.getTime() == 50 ) {
					LP.setFreq(4);
				}
				if (this.Kernel.getTime() == 100 ) {
					LP.setFreq(3);
				}
				if (this.Kernel.getTime() == 150 ) {
					LP.setFreq(2);
				}
				if (this.Kernel.getTime() == 200 ) {
					LP.setFreq(1);
				}
				if (this.Kernel.getTime() == 250 ) {
					LP.setFreq(0);
				}*/
				/**
				 * Change state
				 */
				
				if (LP.getCompteur_idle()> LP.getOwnFieldIntValue("idle_to_standby")) {
					if (LP.getStates() != LEATProcessor.States.STAND_BY)
							LP.setState(LEATProcessor.States.STAND_BY);
				}
				if (LP.getCompteur_idle()> LP.getOwnFieldIntValue("idle_to_sleep")) {
					if (LP.getStates() != LEATProcessor.States.DEEP_SLEEP)
					LP.setState(LEATProcessor.States.DEEP_SLEEP);
					
				}
			}
		}
	}
}
